<%@ page import="eljstl.User" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/12
  Time: 8:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    User user = new User("tom", 18, new Date());
    request.setAttribute("user", user);

    User user1 = new User("tom", 17, new Date());
    User user2 = new User("lily", 18, new Date());
    User user3 = new User("张三", 19, new Date());
    List<User> userList = new ArrayList<User>();
    userList.add(user1);
    userList.add(user2);
    userList.add(user3);
    request.setAttribute("userList", userList);
%>
<h2>使用foreach将数据展示在表格</h2>
<table border="1" width="500" align="center">
    <%--表头--%>
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>生日</th>
    </tr>
    <%--    数据行   --%>
    <%--    iteam：用EL表示试取出request/session/。。。。域中的对象集合
            var：临时变量，含义：集合中的每一个元素（User对象）
            varStatus:循环状态，使用count计数--%>
    <c:forEach items="${userList}" var="u" varStatus="s">
        <c:if test="${s.coun%2==0}">
            <tr bgcolor="aqua">
                <td>${s.count}</td>
                <td>${u.name}</td>
                <td>${u.age}</td>
                <td>${u.birStr}</td>
            </tr>
        </c:if>

        <c:if test="${s.coun%2!=0}">
            <tr bgcolor="fuchsia">
                <td>${s.count}</td>
                <td>${u.name}</td>
                <td>${u.age}</td>
                <td>${u.birStr}</td>
            </tr>
        </c:if>

    </c:forEach>

</table>
</body>
</html>
